package com.zhentao;

import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.PutObjectArgs;

import java.io.FileInputStream;

/**
 * @Date 2024/2/23 10:57
 * @Author xdm
 **/
public class Test {
    public static void main(String[] args) {
        FileInputStream fileInputStream = null;
        try {

            fileInputStream = new FileInputStream("D:\\list.html");
            

            //1.创建minio链接客户端
            MinioClient minioClient = MinioClient.builder().credentials("minioadmin", "minioadmin").endpoint("http://192.168.216.131:19000").build();
            //2.上传
            PutObjectArgs putObjectArgs = PutObjectArgs.builder()
                    .object("list.html")//文件名
                    .contentType("text/html")//文件类型
                    .bucket("test1")//桶名词  与minio创建的名词一致
            //在构建InputStream时，会进行分片操作，分片大小不能小于5MB，大于5GB
            //partSize传入-1，默认按照5MB进行分割
                    .stream(fileInputStream, fileInputStream.available(), -1) //文件流
                    .build();
            ObjectWriteResponse response = minioClient.putObject(putObjectArgs);
                        //获取访问路径
           String path= minioClient.getObjectUrl(putObjectArgs.bucket(), putObjectArgs.object());
            System.out.println(path);
            //http://192.168.73.133:19000/test/list.html

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
